* Replication for Banda and Windett's "Negative Advertising and the Dynamics of Candidate Support"
use "Banda and Windett replication.dta", clear


/* Codebook

year = election year
week = week number, higher numbers mean later in the campaign (closer to election day)
demincumbent = dummy for whether or not the Democratic candidate is an incumbent
repincumbent = dummy for whether or not the Republican candidate is an incumbent
d02 = dummy for whether or not the campaign happened in 2002
d04 = dummy for whether or not the campaign happened in 2004
state = in which state did the campaign happen occur?
governor = 1 is gubernatorial election, 0 is Senatorial election
dempct = DEPENDENT VARIABLE; share of the two party candidate support enjoyed by the Democrat
panelvar = unique ID of each campaign
statepop = state population (U.S. Census)
attackdiff = number of Democratic attack ads in a week - number
	of Republican attack ads in a week, both weighted by state population
attackdiffvol = number of Democratic attack ads in a week - number
	of Republican attack ads in a week, NOT weighted by state population
attackdiffper = INDEPENDENT VARIABLE; percentage of Democratic attack ads in a week - percentage
	of Republican attack ads in a week.

*/


* TABLE 1: contests
bysort governor year: ta state

* Make sure to tsset the data
tsset panelvar week

* TABLE 2: summary stats
sum dempct attackdiffper governor demincumbent repincumbent d02 d04


* Table 3: results
* Main results
sureg (d.dempct l.dempct d.attackdiffper l.attackdiffper governor demincumbent repincumbent) ///
	  (d.attackdiffper l.attackdiffper d.dempct l.dempct governor demincumbent repincumbent), cor
* Bewley transformation to calculate the LRM
sureg (d.dempct l.dempct d.attackdiffper attackdiffper governor demincumbent repincumbent) ///
	  (d.attackdiffper l.attackdiffper d.dempct dempct governor demincumbent repincumbent)
predict dempctfitsur3, xb equation(#1)
predict attackdifffitsur3, xb equation(#2)
* The LRM is captured by the coef of "attackdiffper"
sureg (dempct dempctfitsur3 d.attackdiffper attackdiffper governor demincumbent repincumbent) ///
	  (attackdiffper attackdifffitsur3 d.dempct dempct governor demincumbent repincumbent)


* APPENDIX

*Table A1: Testing for Unit Root i(install xtfisher package first)
use "Banda and Windett replication",clear

xtfisher dempct, lags(1)
xtfisher attackdiffper, lags(1)


* Table A2: Westerlund Error Correction Based Panel Cointegration Test
use "Table A2.dta",clear

xtwest dempct attackdiff, westerlund constant lags(1)

* Table A3: ADL model specification
use "Banda and Windett replication",clear
tsset panelvar week

sureg (dempct l.dempct attackdiffper l.attackdiffper governor demincumbent repincumbent) ///
	  (attackdiffper l.attackdiffper dempct l.dempct governor demincumbent repincumbent), cor	  
estat ic

* Table A4: raw volume of attack ads
sureg (d.dempct l.dempct d.attackdiffvol l.attackdiffvol governor demincumbent repincumbent) ///
	  (d.attackdiffvol l.attackdiffvol d.dempct l.dempct governor demincumbent repincumbent), cor
estat ic
* Bewley for LRM
sureg (d.dempct l.dempct d.attackdiffvol attackdiffvol governor demincumbent repincumbent) ///
	  (d.attackdiffvol l.attackdiffvol d.dempct dempct governor demincumbent repincumbent)
predict dempctfitsur1a, xb equation(#1)
predict attackdifffitsur1a, xb equation(#2)
sureg (dempct dempctfitsur1a d.attackdiffvol attackdiffvol governor demincumbent repincumbent) ///
	  (attackdiffvol attackdifffitsur1a d.dempct dempct governor demincumbent repincumbent)

* Table A5: raw volume of attack ads adjusting for state population
sureg (d.dempct l.dempct d.attackdiff l.attackdiff governor demincumbent repincumbent) ///
	  (d.attackdiff l.attackdiff d.dempct l.dempct governor demincumbent repincumbent), cor
estat ic
* Bewley for LRM
sureg (d.dempct l.dempct d.attackdiff attackdiff governor demincumbent repincumbent) ///
	  (d.attackdiff l.attackdiff d.dempct dempct governor demincumbent repincumbent)
predict dempctfitsur1, xb equation(#1)
predict attackdifffitsur1, xb equation(#2)
sureg (dempct dempctfitsur1 d.attackdiff attackdiff governor demincumbent repincumbent) ///
	  (attackdiff attackdifffitsur1 d.dempct dempct governor demincumbent repincumbent)
